package jpsProject1;

import java.awt.Dimension;
import java.awt.GraphicsEnvironment;
import java.awt.Point;
import java.awt.Rectangle;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 * 
 * @author s0ereN
 *
 */

public class ShowInFrame{
    

    public static void show(JComponent c){
    show("",c);
    }

    public static void show(String title, JComponent c){
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException e1) {
            e1.printStackTrace();
        } catch (InstantiationException e1) {
            e1.printStackTrace();
        } catch (IllegalAccessException e1) {
            e1.printStackTrace();
        } catch (UnsupportedLookAndFeelException e1) {
            e1.printStackTrace();
        }
        JFrame f = new JFrame(title);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(c);
        f.pack();Rectangle r = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
        Dimension d = f.getSize();
        Point p = new Point((int) ((r.getWidth()/2)-(d.getWidth()/2)),(int) ((r.getHeight()/2)-(d.getHeight()/2)));
        f.setLocation(p);
        f.repaint();
        f.setResizable(false);
        f.setVisible(true);
    }
}
